﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Business.Models;
using ETL.Common.Logging;
using ETL.DataAccess;
using ETL.Entity;

namespace ETL.Business.Handlers.ProjectHandlers
{
    public class GetProject
    {
        private readonly ProjectRepository _projectRepository;

        public GetProject()
        {
            _projectRepository = new ProjectRepository();
        }

        public GetProject(ProjectRepository projectRepository)
        {
            _projectRepository = projectRepository;
        }

        public virtual ProjectModel Execute(decimal projectId)
        {
            ProjectModel projectModel = null;

            // try to get from db
            try
            {
                // get from DB
                PROJECT projectData = _projectRepository.GetProjectByProjectId(projectId);

                // Parse to Business Model
                if(projectData != null)
                {
                    projectModel = new ProjectModel(projectData);
                }
            }
            catch (Exception ex)
            {
                LogService.Service.Debug(ex);
            }
            return projectModel;
        }

    }
}
